# This Python file uses the following encoding: utf-8
import urllib
import urllib2
import re
import json
# 将文本文件中的书单内容重新抓取
# 文件内容为  cpId  cpBookId ,如  89		62309
def resetChapter():
    for line in open("test.txt"):
        bookList=re.split("\\s+",line)
        url="http://10.11.78.179:8080/reading-web/resetChapterInfo.jsp?cpId="+bookList[0]+"&cpBookId="+bookList[1]
        req=urllib2.Request(url)
        res_data = urllib2.urlopen(req)
        res = res_data.read()
        print url+"  "

#主动推送书单
# 文件内容为  cpId  cpBookId ,如  89		62309
def pushCpBookList():
    for line in open("test.txt"):
        bookList=re.split("\\s+",line)
        url="http://10.11.78.179:8080/reading-web/mams/updateBooks?sign=7164186&cpId="+bookList[0]
        books=[{"id":bookList[1]}]
        post_data=json.dumps({"books":books})
        req=urllib2.Request(url,headers={"Content-Type":"application/json"})
        urllib2.urlopen(req,post_data)
        print(post_data)

#将文本文件 第一列 转换为a,b,c形式
def txtToLine():
    out="";
    for line in open("test1.txt"):
        lineList=re.split("\\s+",line)
        out+=lineList[0]+","
    print(out)






txtToLine();
# resetChapter();
# pushCpBookList()